#pragma once
#include "Npc.h"
#include "Player.h"
#include "Ingredient.h"
#include "Misc.h"
#include "Potion.h"
#include "Tool.h"
#include "MeleeWeapon.h"
#include "RangedWeapon.h"
#include "Food.h"
#include "Corpse.h"
#include "Shield.h"
#include "Armor.h"
#include "Scroll.h"
#include "Trap.h"
#include "Resource.h"
#include "ItemContainer.h"
#include "Wall.h"
#include "Portal.h"
#include "Door.h"
#include "Util.h"

class Tile;

class Load {
public:
	static Character* loadCharacter(std::ifstream& file) {
		std::string line;
		std::getline(file, line);
		int* tokens = Util::intSplit(line);
		Character* c = NULL;
		switch(tokens[0]) {
		case GT_CH_NPC:
			c = new Npc(file);
			break;
		case GT_CH_PLAYER:
			c = new Player(file);
			break;
		}
		delete[] tokens;
		return c;
	}

	static Item* loadItem(std::ifstream& file) {
		std::string line;
		std::getline(file, line);
		int* tokens = Util::intSplit(line);
		Item* i = NULL;
		switch(tokens[0]) {
		case GT_IT_ARMOR:
			i = new Armor(file);
			break;
		case GT_IT_FOOD:
			i = tokens[1] == FT_CORPSE ? new Corpse(file) : new Food(FoodType(tokens[1]), file);
			break;
		case GT_IT_INGREDIENT:
			i = new Ingredient(file);
			break;
		case GT_IT_MISC:
			i = new Misc(file);
			break;
		case GT_IT_POTION:
			i = new Potion(file);
			break;
		case GT_IT_SHIELD:
			i = new Shield(file);
			break;
		case GT_IT_TOOL:
			i = new Tool(file);
			break;
		case GT_IT_MELEE_WEAPON:
			i = new MeleeWeapon(file);
			break;
		case GT_IT_RANGED_WEAPON:
			i = new RangedWeapon(file);
			break;
		case GT_IT_SCROLL:
			i = new Scroll(file);
			break;
		}
		delete[] tokens;
		return i;
	}

	static Obstacle* loadObstacle(Tile* tile, std::ifstream& file) {
		std::string line;
		std::getline(file, line);
		int* tokens = Util::intSplit(line);
		Obstacle* o = NULL;
		switch(tokens[0]) {
		case GT_OB_DOOR: 
			o = new Door(file);
			break;
		case GT_OB_ITEMCONTAINER:
			o = new ItemContainer(file);
			break;
		case GT_OB_PORTAL:
			o = new Portal(tile, file);
			break;
		case GT_OB_RESOURCE:
			o = new Resource(file);
			break;
		case GT_OB_TRAP:
			o = new Trap(file);
			break;
		case GT_OB_WALL:
			o = new Wall();
			break;
		}
		delete[] tokens;
		return o;
	}
};